package api

import (
	"api-gatwary/basic/globar"
	__ "api-gatwary/basic/proto"
	"api-gatwary/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Videoadd(c *gin.Context) {
	var req request.VideoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "验证失败",
			"data":    false,
		})
		return
	}
	videoadd, err := globar.UserCilenes.Videoadd(c, &__.VideoaddReq{
		Title:  req.Title,
		Url:    req.Url,
		Num:    int64(req.Num),
		Info:   req.Info,
		Status: int64(req.Status),
		Types:  int64(req.Types),
		Image:  req.Image,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "添加失败",
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "添加成功",
		"data":    videoadd,
	})
	return

}

func Videolike(c *gin.Context) {
	var req request.VideoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "验证失败",
			"data":    false,
		})
		return
	}
	videolike, err := globar.UserCilenes.Videolike(c, &__.VideolikeReq{
		Title: req.Title,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "添加失败",
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "搜索成功",
		"data":    videolike,
	})
	return

}

func Videolist(c *gin.Context) {
	var req request.VideoPage
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "验证失败",
			"data":    false,
		})
		return
	}
	videolist, err := globar.UserCilenes.Videolist(c, &__.VideolistReq{
		Page: req.Page,
		Size: req.Size,
	})

	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "查看失败",
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "查询成功",
		"data":    videolist,
	})
	return
}

func VideoShow(c *gin.Context) {
	var req request.VideoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "验证失败",
			"data":    false,
		})
		return
	}
	show, err := globar.UserCilenes.VideoShow(c, &__.VideoShowReq{
		Id: int64(req.Id),
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    http.StatusBadRequest,
			"message": "添加失败",
			"data":    false,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "详情查看成功",
		"data":    show,
	})
	return
}
